<!--  -->
<template>
  <div class="newHome">
    <div class="header">
      <van-icon name="arrow-left" size="18" @click="goBack()" />
      <p>消息列表</p>
      <span></span>
    </div>
    <div class="content">
      <van-tabs v-model="active">
        <van-tab title="消息">
          <van-swipe-cell v-for="(item, idx) in list" :key="idx">
            <dl class="list">
              <dt>
                <img :src="item.img" alt="" />
              </dt>
              <dd>
                <p>
                  <span>{{ item.name }}</span>
                  <span>{{ item.time }}</span>
                </p>
                <p>
                  {{ item.title }}
                </p>
              </dd>
            </dl>
            <template #right>
              <van-button
                square
                type="danger"
                text="删除"
                @click="handleDelete(item.id)"
              />
            </template>
          </van-swipe-cell>
        </van-tab>
        <van-tab title="公告">
          <dl class="inform">
            <dd>
              <p>
                <span>放假通知</span>
                <span>2021年05月27日 13:00:00</span>
              </p>
              <p>五月一日放假</p>
            </dd>
          </dl>
        </van-tab>
      </van-tabs>
    </div>
  </div>
</template>

<script>
import { getMessage, getMesDetete } from "@/api";
export default {
  // 组件状态值
  data() {
    return {
      active: 0,
      list: [],
    };
  },
  // 计算属性
  computed: {},
  // 组件方法
  methods: {
    //返回上一级
    goBack() {
      this.$router.push("/");
    },
    //获取数据
    getList() {
      getMessage().then((res) => {
        console.log(res);
        this.list = res.data.data;
      });
    },
    //删除
    handleDelete(id) {
      getMesDetete({ id }).then((res) => {
        console.log(res);
        this.getList();
      });
    },
  },
  /**
   * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
   */
  created() {
    this.getList();
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<!--使用了scoped属性之后，父组件的style样式将不会渗透到子组件中，-->
<!--然而子组件的根节点元素会同时被设置了scoped的父css样式和设置了scoped的子css样式影响，-->
<!--这么设计的目的是父组件可以对子组件根元素进行布局。-->
<style lang="scss" scoped>
.newHome {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.header {
  width: 100%;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 18px;
  color: #fff;
  background: #4381e6;
  padding: 0 15px;
}
.content {
  flex: 1;
  overflow: auto;
}
.list {
  width: 100%;
  display: flex;
  align-items: center;
  line-height: 30px;
  margin: 10px 0;
  padding: 0 10px;
  border-bottom: 5px solid #eee;
  dt {
    img {
      width: 50px;
      border-radius: 50%;
    }
  }
  dd {
    width: 100%;
    p:nth-child(1) {
      display: flex;
      justify-content: space-between;
      span:nth-child(2) {
        font-size: 14px;
        color: #999;
      }
    }
  }
}
.inform {
  width: 90%;
  line-height: 30px;
  margin: 10px auto;
  padding: 5px 10px;
  border: 1px solid #000;
  dt {
    img {
      width: 50px;
      border-radius: 50%;
    }
  }
  dd {
    width: 100%;
    p:nth-child(1) {
      display: flex;
      justify-content: space-between;
      span:nth-child(2) {
        font-size: 14px;
      }
    }
  }
}
</style>
